package com.learn.project.leetcode.tree;

import java.util.*;

/**
 * TODO
 *
 * @author chenfuyuan
 * @date 2022/3/15 9:27
 */
public class TreeUtil {

    public static List<Integer> print(TreeNode root) {
        List<Integer> result = new ArrayList<>();
        LinkedList<TreeNode> queue = new LinkedList<>();
        queue.add(root);

        while (!queue.isEmpty()) {
            TreeNode node = queue.poll();
            if (node == null) {
                result.add(null);
                continue;
            }
            result.add(node.val);
            if (node.left == null && node.right == null) {
                continue;
            }
            queue.add(node.left);
            queue.add(node.right);

        }

        return result;
    }
}
